#include <numeric>
#include <vector>
#include <list>
#include <iostream>

using namespace std;

int main()
{
    vector<int> vec{1, 2, 3, 4, 5};
    // 对 vec 中的元素求和，和的初值是 0
    int sum1 = accumulate(vec.cbegin(), vec.cend(), 0);
    cout << "sum1: " << sum1 << endl;

    vector<string> v{"a", "b", "c"};
    string sum2 = accumulate(v.cbegin(), v.cend(), string(""));
    cout << "sum2: " << sum2 << endl;

    // 错误：const char* 上没有定义+运算符
    // string sum3 = accumulate(v.cbegin(), v.cend(), "");

    vector<string> roster1{"a", "b", "c", "d"};
    list<const char*> roster2{"a", "b", "c", "d", "e"};
    // 用 == 来比较两个容器中的元素，roster2 中的元素数目应该至少与 roster1 一样多
    cout << "equal: "
        << equal(roster1.cbegin(), roster1.cend(), roster2.cbegin()) 
        << endl;
}